const { default: axios } = require('axios')
const router = require('express').Router()


/**
 * @api {get} /sendcode 获取验证码
 * @apiName 获取验证码信息
 * @apiGroup user
 * @apiDescription 获取验证码信息
 * @apiVersion  1.0.0
 * 
 * @apiParam {String} mobile=''  手机号
 * 
 * 
 * @apiParamExample  {type} 请求示例:
 * {  
 *    mobile:10086,
 * }
 * 
 * @apiSuccess {Number} code 200
 * @apiSuccess {Object} datas 数据信息
 * @apiSuccessExample {type} 返回示例:
 * {
     code:200
     data: null
     msg: "ok"
  },
}
 * 
 */
router.post('/sendcode',(req,res)=>{
    let{mobile}= req.body
    let type ="1"
    axios({
        method:'post',
        url:'https://m.maizuo.com/gateway',
        data:{
            mobile,
            type
        },
        headers:{
            'X-Client-Info': '{"a":"3000","ch":"1002","v":"1.0.0","e":"16425891382355991425318913"}',
            'X-Host': 'mall.user.sms-code.send',
        }
    }).then(data=>{
        res.send(data.data)
    })
})



/**
 * @api {get} /login 用户登录
 * @apiName 用户登录
 * @apiGroup user
 * @apiDescription 用户登录验证
 * @apiVersion  1.0.0
 * 
 * @apiParam {String} mobile=''  手机号
 * @apiParam {String} smsCode=''  验证码
 * 
 * 
 * 
 * @apiParamExample  {type} 请求示例:
 * {  
 *    mobile:10086,
 *    smsCode：10086
 * }
 * 
 * @apiSuccess {Number} code 200
 * @apiSuccess {Object} datas 数据信息
 * @apiSuccessExample {type} 返回示例:
 * {
     code:200
     data: ""
     msg: "ok"
  },
}
 * 
 */
router.post('/login',(req,res)=>{
    let{mobile,smsCode}= req.body
    axios({
        method:'post',
        url:'https://m.maizuo.com/gateway',
        data:{
            mobile,
            smsCode
        },
        headers:{
            'X-Client-Info': '{"a":"3000","ch":"1002","v":"1.0.0","e":"16425891382355991425318913"}',
            'X-Host': 'mall.user.sms-code-login',
        }
    }).then(data=>{
        res.send(data.data)
    })
})


module.exports= router